using IQIGame.Onigao.GamePlay;

namespace IQIGame.Onigao.Logic
{
    public class ExecChangeEntityAudio : BaseServiceExecution
    {
        public override void Execute(LevelRegion region, LevelPlayer player)
        {
            var config = _config as ExecParamChangeEntityAudio;
            if (!config.tagOrMcid.TryGetValue(triggerEntity, out var tagOrMcid))
            {
                LogicLog.LogError($"无法获取到tagOrMcid. config.tagOrMcid: {config.tagOrMcid}");
                return;
            }
            LevelEntity entity = null;
            if (tagOrMcid == 0)
            {
                entity = triggerEntity;
            }
            else
            {
                entity = region.GetEntityByTagOrMcid(tagOrMcid);
            }
            var audioProp = entity.GetOrAddDynProperty<EntityPropAudio>(EntityDynamicPropertyType.Audio);
            audioProp.loopAudioCid = config.loopAudioCid;
            region.NotifyChangeEntityAudio(player, entity, config.loopAudioCid);
        }
    }
}
